
// ------------------------------------------------------------
// ----------------------- class Sidebar ----------------------
// ------------------------------------------------------------

// ---------------------------------------- Sidebar constructor

function Sidebar(sidebarWindow)
{
	this.sidebarWindow = sidebarWindow;
	this.sidebarWindow.sidebar = this;
	this.tools = null;

	this.linkStyleListBox = null;
	this.linkColorListBox = null;

	this.linkStyle = null;
	this.linkColor = null;

	this.sidebarWindow.onload = Tools.createCallback(this.onload, this);
	this.sidebarWindow.onunload = Tools.createCallback(this.onunload, this);
}

// ---------------------------------------- Sidebar onload

Sidebar.prototype.onload = function ()
{
	this.linkStyleListBox = document.getElementById("linkStyleListBox");
	this.linkColorListBox = document.getElementById("linkColorListBox");
	this.linkStyleListBox.onselect = Tools.createCallback(this.onselect, this);
	this.linkColorListBox.onselect = Tools.createCallback(this.onselect, this);
	Tools.notifyObservers(this.sidebarWindow, "golimojo-sidebar-opened");
	this.onselect();
}

// ---------------------------------------- Sidebar initialize

Sidebar.prototype.initialize = function (tools)
{
	this.tools = tools;
	this.linkStyleListBox.value = tools.getPreference("linkStyle") || this.linkStyleListBox.value;
	this.linkColorListBox.value = tools.getPreference("linkColor") || this.linkColorListBox.value;
}

// ---------------------------------------- Sidebar onunload

Sidebar.prototype.onunload = function ()
{
	Tools.notifyObservers(this.sidebarWindow, "golimojo-sidebar-closed");
}

// ---------------------------------------- Sidebar onselect

Sidebar.prototype.onselect = function ()
{
	this.linkStyle = this.linkStyleListBox.value;
	this.linkColor = this.linkColorListBox.value;
	Tools.notifyObservers(this.sidebarWindow, "golimojo-sidebar-select");
	this.tools.setPreference("linkStyle", this.linkStyle);
	this.tools.setPreference("linkColor", this.linkColor);
}

// ------------------------------------------------------------
// ---------------------- initialization ----------------------
// ------------------------------------------------------------

try
{
	var gSidebar = new Sidebar(window);
}
catch (e)
{
	alert(Log.inspectObject(e));
	Log.print(e);
}
